/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-20
 * Time: 11:59
 */
//https://leetcode.cn/problems/binary-search/
public class Test {
    public static int search(int[] nums, int target) {
        if(nums.length==0){
            return -1;
        }
        int p1=0,p2=nums.length-1,p=(p1+p2)/2;
        while(p1<=p2){
            if(nums[p]<target){
                p1=p+1;
            }
            else if(nums[p]>target){
                p2=p-1;
            }
            else{
                return p;
            }
            p=(p1+p2)/2;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,9,11};
        System.out.println(search(arr,14));
    }
}
